<!--
 * @Author: your name
 * @Date: 2022-03-09 14:42:00
 * @LastEditTime: 2022-03-09 15:04:16
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day09\6-事件委托.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload=function(){
            var list=document.getElementById('list');
            var one=document.getElementById('one');
            var two=document.getElementById('two');
            var three=document.getElementById('three');
         /*    console.log(list);
            function handler1(){
                console.log(this.id);
                this.innerHTML='我是第一个孩子'
            }
            function handler2(){
                console.log(this.id);
                this.innerHTML='我是第二个孩子'
            }

            function handler3(){
                console.log(this.id);
                this.innerHTML='我是第三个孩子'
            }


            one.addEventListener('click',handler1,false);
           two.addEventListener('click',handler2,false);
           three.addEventListener('click',handler3,false) */
           list.onclick=function(event){
             var target=event.target ;
              switch(target.id){
                case 'one': target.innerHTML='我是第一个孩子'; break;
                case 'two': target.innerHTML='我是第er个孩子'; break;
                case 'three': target.innerHTML='我是第3个孩子'; break;
                default:
            };
          
            console.log(event);
           }
        }
    </script>
</head>
<body>
    <ul id="list"> 
        <li id="one">11</li>
        <li id="two">122221</li>
        <li id="three">33</li>
    </ul>
</body>
</html>